using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace JTC.MiniCommerce.Core
{
	/// <summary>
	/// Strongly-typed collection for the Log class.
	/// </summary>
	[Serializable]
	public partial class LogCollection : ActiveList<Log, LogCollection> 
	{	   
		public LogCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the MiniCommerce_Core_Log table.
	/// </summary>
	[Serializable]
	public partial class Log : ActiveRecord<Log>
	{
		#region .ctors and Default Settings
		
		public Log()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public Log(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public Log(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public Log(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("MiniCommerce_Core_Log", TableType.Table, DataService.GetInstance("MiniCommerceProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarLogId = new TableSchema.TableColumn(schema);
				colvarLogId.ColumnName = "LogId";
				colvarLogId.DataType = DbType.Int32;
				colvarLogId.MaxLength = 0;
				colvarLogId.AutoIncrement = true;
				colvarLogId.IsNullable = false;
				colvarLogId.IsPrimaryKey = true;
				colvarLogId.IsForeignKey = false;
				colvarLogId.IsReadOnly = false;
				colvarLogId.DefaultSetting = @"";
				colvarLogId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLogId);
				
				TableSchema.TableColumn colvarLogDate = new TableSchema.TableColumn(schema);
				colvarLogDate.ColumnName = "LogDate";
				colvarLogDate.DataType = DbType.DateTime;
				colvarLogDate.MaxLength = 0;
				colvarLogDate.AutoIncrement = false;
				colvarLogDate.IsNullable = false;
				colvarLogDate.IsPrimaryKey = false;
				colvarLogDate.IsForeignKey = false;
				colvarLogDate.IsReadOnly = false;
				
						colvarLogDate.DefaultSetting = @"(getutcdate())";
				colvarLogDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLogDate);
				
				TableSchema.TableColumn colvarThread = new TableSchema.TableColumn(schema);
				colvarThread.ColumnName = "Thread";
				colvarThread.DataType = DbType.String;
				colvarThread.MaxLength = 255;
				colvarThread.AutoIncrement = false;
				colvarThread.IsNullable = false;
				colvarThread.IsPrimaryKey = false;
				colvarThread.IsForeignKey = false;
				colvarThread.IsReadOnly = false;
				colvarThread.DefaultSetting = @"";
				colvarThread.ForeignKeyTableName = "";
				schema.Columns.Add(colvarThread);
				
				TableSchema.TableColumn colvarLogLevel = new TableSchema.TableColumn(schema);
				colvarLogLevel.ColumnName = "LogLevel";
				colvarLogLevel.DataType = DbType.String;
				colvarLogLevel.MaxLength = 50;
				colvarLogLevel.AutoIncrement = false;
				colvarLogLevel.IsNullable = false;
				colvarLogLevel.IsPrimaryKey = false;
				colvarLogLevel.IsForeignKey = false;
				colvarLogLevel.IsReadOnly = false;
				colvarLogLevel.DefaultSetting = @"";
				colvarLogLevel.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLogLevel);
				
				TableSchema.TableColumn colvarLogger = new TableSchema.TableColumn(schema);
				colvarLogger.ColumnName = "Logger";
				colvarLogger.DataType = DbType.String;
				colvarLogger.MaxLength = 255;
				colvarLogger.AutoIncrement = false;
				colvarLogger.IsNullable = false;
				colvarLogger.IsPrimaryKey = false;
				colvarLogger.IsForeignKey = false;
				colvarLogger.IsReadOnly = false;
				colvarLogger.DefaultSetting = @"";
				colvarLogger.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLogger);
				
				TableSchema.TableColumn colvarLogMessage = new TableSchema.TableColumn(schema);
				colvarLogMessage.ColumnName = "LogMessage";
				colvarLogMessage.DataType = DbType.String;
				colvarLogMessage.MaxLength = 4000;
				colvarLogMessage.AutoIncrement = false;
				colvarLogMessage.IsNullable = false;
				colvarLogMessage.IsPrimaryKey = false;
				colvarLogMessage.IsForeignKey = false;
				colvarLogMessage.IsReadOnly = false;
				colvarLogMessage.DefaultSetting = @"";
				colvarLogMessage.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLogMessage);
				
				TableSchema.TableColumn colvarLogInfo = new TableSchema.TableColumn(schema);
				colvarLogInfo.ColumnName = "LogInfo";
				colvarLogInfo.DataType = DbType.String;
				colvarLogInfo.MaxLength = 4000;
				colvarLogInfo.AutoIncrement = false;
				colvarLogInfo.IsNullable = false;
				colvarLogInfo.IsPrimaryKey = false;
				colvarLogInfo.IsForeignKey = false;
				colvarLogInfo.IsReadOnly = false;
				colvarLogInfo.DefaultSetting = @"";
				colvarLogInfo.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLogInfo);
				
				TableSchema.TableColumn colvarApplication = new TableSchema.TableColumn(schema);
				colvarApplication.ColumnName = "Application";
				colvarApplication.DataType = DbType.String;
				colvarApplication.MaxLength = 50;
				colvarApplication.AutoIncrement = false;
				colvarApplication.IsNullable = false;
				colvarApplication.IsPrimaryKey = false;
				colvarApplication.IsForeignKey = false;
				colvarApplication.IsReadOnly = false;
				colvarApplication.DefaultSetting = @"";
				colvarApplication.ForeignKeyTableName = "";
				schema.Columns.Add(colvarApplication);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["MiniCommerceProvider"].AddSchema("MiniCommerce_Core_Log",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("LogId")]
		public int LogId 
		{
			get { return GetColumnValue<int>("LogId"); }

			set { SetColumnValue("LogId", value); }

		}

		  
		[XmlAttribute("LogDate")]
		public DateTime LogDate 
		{
			get { return GetColumnValue<DateTime>("LogDate"); }

			set { SetColumnValue("LogDate", value); }

		}

		  
		[XmlAttribute("Thread")]
		public string Thread 
		{
			get { return GetColumnValue<string>("Thread"); }

			set { SetColumnValue("Thread", value); }

		}

		  
		[XmlAttribute("LogLevel")]
		public string LogLevel 
		{
			get { return GetColumnValue<string>("LogLevel"); }

			set { SetColumnValue("LogLevel", value); }

		}

		  
		[XmlAttribute("Logger")]
		public string Logger 
		{
			get { return GetColumnValue<string>("Logger"); }

			set { SetColumnValue("Logger", value); }

		}

		  
		[XmlAttribute("LogMessage")]
		public string LogMessage 
		{
			get { return GetColumnValue<string>("LogMessage"); }

			set { SetColumnValue("LogMessage", value); }

		}

		  
		[XmlAttribute("LogInfo")]
		public string LogInfo 
		{
			get { return GetColumnValue<string>("LogInfo"); }

			set { SetColumnValue("LogInfo", value); }

		}

		  
		[XmlAttribute("Application")]
		public string Application 
		{
			get { return GetColumnValue<string>("Application"); }

			set { SetColumnValue("Application", value); }

		}

		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(DateTime varLogDate,string varThread,string varLogLevel,string varLogger,string varLogMessage,string varLogInfo,string varApplication)
		{
			Log item = new Log();
			
			item.LogDate = varLogDate;
			
			item.Thread = varThread;
			
			item.LogLevel = varLogLevel;
			
			item.Logger = varLogger;
			
			item.LogMessage = varLogMessage;
			
			item.LogInfo = varLogInfo;
			
			item.Application = varApplication;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varLogId,DateTime varLogDate,string varThread,string varLogLevel,string varLogger,string varLogMessage,string varLogInfo,string varApplication)
		{
			Log item = new Log();
			
				item.LogId = varLogId;
				
				item.LogDate = varLogDate;
				
				item.Thread = varThread;
				
				item.LogLevel = varLogLevel;
				
				item.Logger = varLogger;
				
				item.LogMessage = varLogMessage;
				
				item.LogInfo = varLogInfo;
				
				item.Application = varApplication;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string LogId = @"LogId";
			 public static string LogDate = @"LogDate";
			 public static string Thread = @"Thread";
			 public static string LogLevel = @"LogLevel";
			 public static string Logger = @"Logger";
			 public static string LogMessage = @"LogMessage";
			 public static string LogInfo = @"LogInfo";
			 public static string Application = @"Application";
						
		}

		#endregion
	}

}

